//
//  ConnectViewController.m
//  WeiWeiApp
//
//  Created by 高继鹏 on 15/10/15.
//  Copyright © 2015年 GaoJipeng. All rights reserved.
//

#import "ConnectViewController.h"
#import "ConnectCell.h"

@interface ConnectViewController (){
    UITableView *_tableView;
    NSMutableArray *tableSource;
    NSString *phoneNum;
    UIWebView *_phoneCallWebView;
}

@end

@implementation ConnectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self titleWithSting:@"联系Ta"];
    [self addBtnOnNavWithTitle:@"预约" andImageName:@"返回" andTarget:self andAction:@selector(backAction) andFrame:CGRectMake(0, 0, 45, 20) andDirection:left];
    _tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    _tableView.backgroundColor = BACKGROUDCOLOR;
    [_tableView registerNib:[UINib nibWithNibName:@"ConnectCell" bundle:nil] forCellReuseIdentifier:NSStringFromClass([ConnectCell class])];
    [self.view addSubview:_tableView];
    [self createData];
    
}
-(void)backAction
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)createData
{
    tableSource = [[NSMutableArray alloc] init];
    [tableSource addObject:self.infoDate];
    _tableView.delegate   = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_tableView reloadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return tableSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    ConnectCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ConnectCell class]) forIndexPath:indexPath];
    cell.contentView.backgroundColor =BACKGROUDCOLOR;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.nameLabel.textColor = FiveOneColor;
    cell.nameLabel.text = tableSource[indexPath.row][0];
    cell.phoneLabel.text = tableSource[indexPath.row][1];
    phoneNum = tableSource[indexPath.row][1];
    [cell.phoneBtn addTarget:self action:@selector(phoneAction:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (void)phoneAction:(UIButton *)sender
{
    NSURL *phoneURL = [NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",phoneNum]];
    if ( !_phoneCallWebView ) {
        _phoneCallWebView = [[UIWebView alloc]initWithFrame:CGRectZero];// 这个webView只是一个后台的容易 不需要add到页面上来 效果跟方法二一样 但是这个方法是合法的
    }
    [_phoneCallWebView loadRequest:[NSURLRequest requestWithURL:phoneURL]];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
